/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package org.amarena2d.examples.scenes;

import com.android1.amarena2d.actions.base.RepeatForever;
import com.android1.amarena2d.actions.base.Sequence;
import com.android1.amarena2d.actions.movement.MoveBy;
import com.android1.amarena2d.nodes.FpsLabel;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.particle.Emitter;
import com.android1.amarena2d.nodes.particle.ParticleSystem;
import com.android1.amarena2d.nodes.particle.effects.TestEffect;
import com.android1.amarena2d.texture.Textures;
import com.badlogic.gdx.graphics.Color;
import org.amarena2d.examples.Example;

@Example(name = "Particle Touch", category = "Particle System")
public class ParticleTouchTestScene extends Scene {

    final Emitter emitter;

    public ParticleTouchTestScene() {


        //place the default FPS counter into the screen
        add(new FpsLabel(10, 20, Color.WHITE));

        ParticleSystem system = new ParticleSystem(Textures.$("particle.png").get());

        emitter = system.createEmitter(new TestEffect(), 0, 0);

        //Emitter can be transformed
        emitter.transform().setScale(1.5F);

        add(system);
    }


    @Override
    protected void onEnterFinished() {

        touch().makeTouchable(this);

        float height = engine.getCamera().getHeight();
        float width = engine.getCamera().getWidth();
        emitter.setXY(20, height / 2);
        MoveBy moveBy = MoveBy.$(width - 100, 0, 3);
        emitter.action().run(RepeatForever.$(Sequence.$(moveBy, moveBy.reverse())));
        emitter.play();
    }

    @Override
    public boolean onTouchDown(float x, float y, int pointer, boolean isHit) {
        if (!emitter.isPlaying())
            emitter.play();
        emitter.action().pauseAll();
        emitter.setXY(x - 20, y - 20);
        return true;
    }

    @Override
    public boolean onTouchDragged(float x, float y, int pointer, boolean isHit) {
        if (!emitter.isPlaying())
            emitter.play();
        emitter.setXY(x - 20, y - 20);
        return true;
    }

    @Override
    public boolean onTouchUp(float x, float y, int pointer, boolean isHit) {
        emitter.stop();
        return true;
    }
}